//书写spu的接口
import request from "../../../utils/request";
//接口地址
enum API {
  SPU_URL = '/admin/product/',
  GETGRAND_URL = '/admin/product/baseTrademark/getTrademarkList',
  GETIMAGE_URL = '/admin/product/spuImageList/',
  GETATTR_URL = '/admin/product/spuSaleAttrList/',
  GETSALLATTR_URL = '/admin/product/baseSaleAttrList',
  SAVEINFO_URL = '/admin/product/saveSpuInfo',
  UPDATEINFO_URL = '/admin/product/updateSpuInfo',
  DELETE_URL = '/admin/product/deleteSpu/'
}

//定义接口
export const reqSpu = (page: number, limit: number, category3Id: number | string) => request.get<any, any>(API.SPU_URL + `${page}/${limit}?category3Id=${category3Id}`)
//定义获取品牌的方法
export const reqGetGrand = () => request.get<any, any>(API.GETGRAND_URL)
//定义获取照片墙的方法
export const reqGetImage = (spuId: number) => request.get<any, any>(API.GETIMAGE_URL + spuId)
//定义获取属性的方法
export const reqGetAttr = (spuId: number) => request.get<any, any>(API.GETATTR_URL + spuId)
//定义获取【版本】，【颜色】，【尺码】
export const reqGetSall = () => request.get<any, any>(API.GETSALLATTR_URL)
//保存（追加）或者更新
export const reqSaveOrUpdate = (data: any) => {
  if (data.id) {
    request.post<any, any>(API.UPDATEINFO_URL, data)
  } else {
    request.post<any, any>(API.SAVEINFO_URL, data)
  }
}
//删除spu
export const reqDeleteSpu = (spuId: number) => request.delete(API.DELETE_URL + spuId)